package com.hallowd.purcom;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;


public class wellcomePageActivity extends Activity {
    Activity myActivity2;
    Button myCreateCommPage;
    Button mySearchButton;
    Button homeButton;
    public EditText mySearchText;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wellcome_page);


        myActivity2 = this;

        mySearchText = (EditText) findViewById(R.id.searchPlainText);
        myCreateCommPage = (Button) findViewById(R.id.createCommunityButton);
        myCreateCommPage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(myActivity2, CreateCommunity.class);
                startActivity(intent);
            }
        });

        homeButton = (Button) findViewById(R.id.homeButton);
        homeButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(myActivity2, wellcomePageActivity.class);
                startActivity(intent);
            }
        });


        mySearchButton = (Button) findViewById(R.id.searchButton);
        mySearchButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(myActivity2, SearchActivity.class);
                intent.putExtra("searchedItem",mySearchText.getText().toString());
                startActivity(intent);
            }


        });
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_wellcome_page, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

   /* private class CreateCommAsyncTask extends AsyncTask<String, Integer, String> {
        @Override
        protected String doInBackground(String... params) {
            String url = "http://titan.cmpe.boun.edu.tr:8089/purcom/mobile/user/signin";
            String email = mEmail.getText().toString();
            String password = mPassword.getText().toString();
            url = url + "?email="+email+"&password="+password;

            HttpClient httpclient = new DefaultHttpClient();
            HttpUriRequest request = new HttpGet(url);

            try {
                HttpResponse response = httpclient.execute(request);
                if (response.getStatusLine().getStatusCode() == 200) {
                    BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent(), "UTF-8"));

                    StringBuilder builder = new StringBuilder();
                    for (String line = null; (line = reader.readLine()) != null; ) {
                        builder.append(line).append("\n");
                    }

                    Log.d(TAG, "Login " + builder.toString());
                    return builder.toString();
                }
                else
                    Log.d(TAG, "Login Failed");
            } catch (IOException e) {
                Log.d(TAG, "Connection problem occured");
            }

            return null;
        }

        protected void onPostExecute(String result) {
            //result = "true";
            String str = "true";
            result = result.trim(); //result ın sonunda boşluk koyuyor onları siliyoruz.

            if(result.equals(str)){

                Intent myintent = new Intent(myActivity,wellcomePageActivity.class);
                startActivity(myintent);
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this);
            builder.setMessage(result)
                    .setTitle("Login Result")
                    .setPositiveButton(android.R.string.ok, null);
            AlertDialog dialog = builder.create();
            dialog.show();
        }
    }*/

}

